package com.wings4.school.student

class StudentType {
    String studentTypeName;
    String description;
    Boolean status;
    Date createDate;

    static  mapping = {
        createDate(sqlType: 'datetime');
    }

    static constraints = {
        status(nullable: true);
        description(nullable: true);
    }

    public static void initialize() {
        def insertSql = [
                ["Reguler","Regular Student",true,new Date()],
                ["Irregular","Irregular Student",true,new Date()]

        ]
        if (StudentType.countByStudentTypeName("Reguler") < 1 && insertSql) {
            insertSql.each {
                StudentType studentType =null;
                try{
                    studentType = new StudentType(studentTypeName: it[0], description: it[1],status: it[2],createDate: [3]);
                    studentType.save(flush: true);
                } catch(Exception e){
                    e.printStackTrace();
                }
            }

        }
    }
}
